package l1j.server.server.command.executor;

import java.util.StringTokenizer;
import java.util.logging.Logger;

import l1j.server.server.datatables.ItemTable;
import l1j.server.server.model.Instance.L1PcInstance;
import l1j.server.server.serverpackets.S_SerchDrop;
import l1j.server.server.serverpackets.S_SystemMessage;

public class L1SerchDroplist implements L1CommandExecutor{
	private static Logger _log = Logger.getLogger(L1Action.class.getName());
	
	private L1SerchDroplist() {
	}
	
	public static L1CommandExecutor getInstance() {
		return new L1SerchDroplist();
	}
	
	@Override
	public void execute(L1PcInstance pc, String cmdName, String arg) {
		try {
			StringTokenizer tok = new StringTokenizer(arg);
			String nameid = tok.nextToken();

			int itemid = 0;
			try {
				itemid = Integer.parseInt(nameid);
			} catch (NumberFormatException e) {
				itemid = ItemTable.getInstance().findItemIdByNameWithoutSpace(nameid);
				if (itemid == 0) {
					pc.sendPackets(new S_SystemMessage("\\fY해당 아이템이 발견되지 않았습니다."));
					return;
				}
			}
			pc.sendPackets(new S_SerchDrop(itemid));
		} catch (Exception e) {
			//   _log.log(Level.SEVERE, e.getLocalizedMessage(), e);
			pc.sendPackets(new S_SystemMessage("\\fY .드랍 [itemid 또는 name]를 입력해 주세요."));
			pc.sendPackets(new S_SystemMessage("\\fY 아이템 이름을 공백없이 정확히 입력해야 합니다."));
			pc.sendPackets(new S_SystemMessage("\\fY ex) .드랍 마법서(디스인티그레이트) -- > 검색 O"));
			pc.sendPackets(new S_SystemMessage("\\fY ex) .드랍 디스 -- > 검색 X"));
		}
	}
}
